#include <stdio.h>

int main() {
	int num[15] = {0};
    printf("输入15个数:\n");
    for(int i=0;i<15;i++){
    	scanf("%d",&num[i]);
	}

	//int num[15] = {1, 2, 3, 4, 5, 6, 43, 21, 34, 9, 10, 12, 13, 45, 15};
    int i, j, temp;
    // 冒泡排序降序排列
    for (i = 0; i < 14; i++) {
        for (j = 0; j < 14 - i; j++) {
            if (num[j] < num[j + 1]) {
                temp = num[j];
                num[j] = num[j + 1];
                num[j + 1] = temp;
            }
        }
    }
    printf("排序后：\n");
    for (i = 0; i < 15; i++) {
        printf("%d ", num[i]);
    }
    printf("\n");
    // 二分查找
    int m, left = 0, right = 14, mid, flag = 0;
    printf("输入要查找的数：\n");
    scanf("%d", &m);
    while (left <= right) {
        mid = (left + right) / 2;
        if (m == num[mid]) {
            printf("找到了，下标为 %d\n", mid);
            flag = 1;
            break;
        } else if (m > num[mid]) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    if (flag == 0) {
        printf("该数不存在！\n");
    }
    return 0;
}